<html>
    <head>
        <title>Resize Window</title>

        <!-- The <script> tag should be placed before the <HTA> tag -->
        <!-- In order to do window resize before the window created -->
        <!-- You have to notice that once the browser parse through the <HTA> tag  -->
        <!-- The window should be created -->
        <script>
            var windowWidthRatio = 0.97;
            var windowHeightRatio = 0.8;

            function CloseTheWindow(){
                window.close();
            }

            function CalculateWindowPosition(windowWidth, windowHeight){
                var xPos = (screen.width - windowWidth) / 2;
                var yPos = (screen.height - windowHeight) / 2;
                return [xPos, yPos];
            }

            function BeforeWindowOnload_Setup(){
                window.windowWidth = window.windowWidthRatio * screen.width;
                window.windowHeight = window.windowHeightRatio * screen.height;
            }

            function BeforeWindowOnload_Loop(){
                window.resizeTo(window.windowWidth, window.windowHeight);
                var position = CalculateWindowPosition(window.windowWidth, window.windowHeight);
                window.windowLeft = position[0];
                window.windowUp = position[1];
                window.moveTo(window.windowLeft, window.windowUp);
            }

            // The following script will run BEFORE the window loads
            while (true) {
                BeforeWindowOnload_Setup();
                try {
                    BeforeWindowOnload_Loop();
                    break;
                } catch (e) {
                    continue;
                }
            }
        </script>

        <HTA:Application
         ApplicationName="Message Box"
         ID="MsgBox"
         InnerBorder="no"
         MaximizeButton="no"
         MinimizeButton="no"
         Scroll="no"
         ContextMenu="no"
         Selection="no"
         SingleInstance="yes"
         Border="thin"
         Icon="colorcpl.exe"
        />
        <!-- ContextMenu: 右键菜单 -->
        <!-- Border=thin: 禁用鼠标拖动边框缩放窗口大小 -->
        <!-- Icon=".exe": 使用在System32文件夹中的exe图标 -->
    </head>
    <body>
        <h1>Hello World!</h1>
        <button onclick="CloseTheWindow()">Close The Window</button>
    </body>
</html>
